<?php
namespace Admin\Util\lib;
use Admin\Util\lib\YZTokenClient;


class YouZanApiFunction {

    /*
     * 获取商品批发信息
     * $alias 商品别名
     * $access_token
     */
    public function Get_YZ_PF_Goods($alias,$access_token){
        $method = 'youni.erp.goods.item';//'kdt.items.custom.get';//要调用的api名称
        $methodVersion = '1.0.0/getdetail';//要调用的api版本号
        $params = array(
            'alias' => $alias,
        );
        $files = array();
        $client = new YZTokenClient($access_token);
        $goodsinfo = $client->post2($method, $methodVersion, $params, $files);
        return $goodsinfo;
    }
    /*
      * 有赞发货
      * $confirm 订单id
      * $access_token
      */
    public function Shipments_API($confirm,$access_token) {
        $context = stream_context_create(array('http' => array('ignore_errors' => true)));
        $urlss = 'http://www.goonee.me/zhechaojson.index.php?confirm=' . $confirm . '&token=' . urlencode($access_token);
        $content = file_get_contents($urlss, FALSE, $context);
        $orderlistass = json_decode($content, TURE);
        if (intval($orderlistass['response']['is_success']) == 1) {
            return 1;
        } else {
            return 0;
        }

    }

    /*
   * 下架操作
   */
    public function delisting($num_iid,$access_token){
        $client = new YZTokenClient($access_token);
        $method = 'youni.erp.goods.item'; //要调用的api名称
        $api_version = '1.0.0/delisting'; //要调用的api版本号

        $my_params =[
            'num_iid'=>$num_iid,
            'fields' =>$num_iid,
        ];
        $SJdata = $client->get2($method, $api_version, $my_params, $my_files =array());
        if($SJdata['response']['item']['num_iid']){
            return 1;
        }else{
            return 0;
        }
    }
    /*
     * 上架操作
     */
    public function listing($num_iid,$access_token){
        $client = new YZTokenClient($access_token);
        $method = 'youni.erp.goods.item'; //要调用的api名称
        $api_version = '1.0.0/listing'; //要调用的api版本号

        $my_params =[
            'num_iid'=>$num_iid,
            'fields' =>$num_iid,
        ];
        $SJdata = $client->get2($method, $api_version, $my_params, $my_files =array());
        if($SJdata['response']['item']['num_iid']){
            return 1;
        }else{
            return 0;
        }
    }
    /*
     * 商品删除操作
     */
    public function delete($item_id,$access_token){
        $client = new YZTokenClient($access_token);
        $method = 'youzan.item.delete'; //要调用的api名称
        $api_version = '3.0.0'; //要调用的api版本号

        $my_params =[
            'item_id' => $item_id
        ];
        $SJdata = $client->post($method, $api_version, $my_params, $my_files =array());
        if($SJdata['response']['is_success']){
            return 1;
        }else{
            return 0;
        }
    }


}
